package Boke2;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class BlockingQueue1 {
   public static int a=0;
   public final int b=4;
    public static void main(String[] args) throws InterruptedException {

        BlockingQueue<Integer> blockingQueue=new LinkedBlockingQueue<>();
        //创建生产者线程t1
        Thread t1=new Thread(()->{
            while(a<100){
                try {
                    blockingQueue.put(a);
                    System.out.println("t1生产了一个："+a);
                    Thread.sleep(500);
                    a++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        //创建消费者t2
        Thread t2=new Thread(()->{
            while(true){
                try {
                    System.out.println("t2消费了"+blockingQueue.take());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
    }
}
